const express = require('express');
const cors = require('cors');
const serveRouter = require('./routers/serve')
const inforRouter = require('./routers/infor')
const loginRouter = require('./routers/login')
const csRouter = require('./routers/CustomerService')
const coRouter = require('./routers/cart&order')
const collectRouter = require('./routers/collect')
const userRouter = require('./routers/user')
const app = express()
app.listen(8888,()=>{
    console.log('服务器启动成功');
})

// 将post传参转为对象
app.use(express.urlencoded({
    extended: true
}))
app.use(cors())
//路由器使用
app.use('/serve',serveRouter)
app.use('/infor',inforRouter)
app.use('/login',loginRouter)
app.use('/cs',csRouter)
app.use('/co',coRouter)
app.use('/collect',collectRouter)
app.use('/user',userRouter)

// 错误处理中间件
app.use( (err,req,res,next)=>{
    console.log(err)
    res.status(500).send({code:500,msg:'服务器端错误'})
} )